package org.cyz.tools.controller;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXComboBox;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import org.cyz.tools.core.ContextManager;
import org.cyz.tools.core.assembly.UIRefresh;
import org.cyz.tools.core.manager.WindowManager;
import org.cyz.tools.service.NewConnectionService;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * @program: RedisGUI
 * @description: menu controller
 * @author: Chenyz
 * @create: 2020-08-10 10:21
 **/
public class NewConnectionController extends UIRefresh implements Initializable {



    //tab 选项卡是否选择过
    private static boolean isSelect = false;

    @FXML
    public JFXComboBox connTimeout;
    @FXML
    public JFXComboBox execTimeout;
    @FXML
    public JFXComboBox findDatabaseTimeout;

    @FXML
    public TextField urlNameText;
    @FXML
    public TextField addressUrlText;
    @FXML
    public TextField portText;
    @FXML
    public TextField passWordText;
    @FXML
    public TextField userNameText;

    /**
     * SSL-TLS
     **/
    @FXML
    public JFXButton pubKeyBtn;
    @FXML
    public TextField pubKey;

    @FXML
    public JFXButton authKeyBtn;
    @FXML
    public TextField authKey;

    @FXML
    public JFXButton priKeyBtn;
    @FXML
    public TextField priKey;

    @FXML
    public JFXButton testButton;
    @FXML
    public JFXButton acceptButton;
    @FXML
    public JFXButton closeButton;
    /**
     * ssh方式授权
     **/
    @FXML
    public JFXButton sshPubKeyBtn;
    @FXML
    public JFXButton sshPriKeyBtn;




    private NewConnectionService service=null;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        ContextManager.ctrManager.addController(this.getClass().getSimpleName(), this);

        service=new NewConnectionService(
                connTimeout,
                execTimeout,
                findDatabaseTimeout,
                urlNameText,
                addressUrlText,
                portText,
                passWordText,
                userNameText,
                pubKeyBtn,
                pubKey,
                authKeyBtn,
                authKey,
                priKeyBtn,
                priKey,
                testButton,
                acceptButton,
                closeButton,
                sshPubKeyBtn,
                sshPriKeyBtn
        );
        //初始化监听
        service.initListener();
        //初始化数据
        service.initData();
        //测试使用数据
        service.testData();
    }


    public void advancedSetting(MouseEvent mouseEvent){

    }

    /**
     * 退出系统
     *
     * @param mouseEvent
     */
    public void closeWin(MouseEvent mouseEvent) {
        WindowManager.stage.close();
    }

}
